#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int S = 1<<13;
const int N = 13;

int n,m,ban;
ll h[2][S],*h0,*h1;

void solve(){
	n = in,m = in; h0 = h[0],h1 = h[1]; memset(h1,0,(1<<m+1)*8); h1[0] = 1; 
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			ban = in ^ 1; swap(h0,h1);
			memset(h1,0,(1<<m+1)*8);
			for(int s = 0;s < (1<<m+1);s++){
				int left = s >> j & 1,up = s >> j + 1 & 1;
				if(ban){
					if(!left && !up) h1[s] += h0[s];
				}else{
					h1[s ^ 3 << j] += h0[s];
					if(left != up) h1[s] += h0[s];
				}
			}
		}
		swap(h0,h1); memset(h1,0,(1<<m+1)*8);
		for(int s = 0;s < (1<<m);s++) h1[s<<1] += h0[s];
	}
	printf("%lld\n",h1[0]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	int t = in;
	while(t--) solve();	
	return 0;
}

